package com.xy.controller;

import com.xy.service.TestService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author xxy
 * @date 2022/1/5 13:44
 */
@RestController
public class TestController {


    private final TestService testService;

    public TestController(TestService testService) {
        this.testService = testService;
    }


    /*@RequestMapping("/test")
    public Map test() {

        Map result = new HashMap();

        long num = 0;
        long time = 10;
        String reqId = UUID
                .randomUUID()
                .toString()
                .replace("-", "") + (new Random()
                .nextInt(9000) + 1000);

        Thread t1 = null;
        try {
            // 尝试获取锁
            redisLock.tryGetLock(reqId, time);

            // 创建 子线程续命
            t1 = redisLock.createLifeThread(time, reqId);
            // t1 开启守护线程
            t1.setDaemon(true);
            // 启动 t1 线程
            t1.start();

            result.put("num", testService.updateNum());
            result.put("reqId", reqId);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 中断线程
            t1.interrupt();
            // 释放锁
            redisLock.unLock(reqId);
        }
        return result;
    }*/


    @RequestMapping("/test")
    public Map test() {
        return testService.test();
    }


}
